#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> insertionSort(vector<int>& nums){
    vector<int> index;   
    for(int i=1;i<nums.size();i++)
    {
        for(int j=0;j<i+1;j++)
        {
            //将第i个元素插入到第一个比它大的元素的前面
            if(nums[i]<nums[j])
            {
                //在nums[j]前面插入nums[i]
                nums.insert(nums.begin()+j,nums[i]);
                nums.erase(nums.begin()+i+1);
                break;
            }
        }
        cout<<"The "<<i+1<<"th sorted array is:"<<endl;
        for(int j=0;j<nums.size();++j)
        {
            cout<<nums[j]<<" ";
        }
        cout<<endl;
    }
    return nums;

}

int main(){
    cout<<"Enter the numbers:"<<endl;
    vector<int> v;
    int n;
    while(n!=-1)
    {
        cin>>n;
        v.push_back(n);
    }
    v.pop_back();
    
    vector<int> result = insertionSort(v);
    cout<<"The sorted array is:"<<endl;
    for(int i=0;i<result.size();++i)
    {
        cout<<result[i]<<" ";
    }
    return 0;
}
